package com.fattyCorps.battle.service.battle.behavior.state;

import com.fattyCorps.battle.service.battle.Battle;
import com.fattyCorps.battle.service.battle.behavior.Behavior;
import com.fattyCorps.battle.service.battle.behavior.BhvBlackboard;
import com.fattyCorps.battle.service.battle.behavior.condition.EftTrgCnd;
import com.fattyCorps.battle.service.battle.data.BattleHero;
import com.fattyCorps.battle.service.battle.effect.Effect;
import com.fattyCorps.common.obj.config.SkillBehaviorMould;
import com.fattyCorps.common.util.fsm.FsmState;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

// 根据目标当前状态，筛选造成的效果
@Slf4j
public class SEffectFilter extends FsmState {
    @Override
    public void onEnter() {
        SkillBehaviorMould cfg = (SkillBehaviorMould)getBlackboard(BhvBlackboard.BHV_CFG);
        Behavior bhv = (Behavior)getBlackboard(BhvBlackboard.BHV);
        BattleHero owner = (BattleHero)getBlackboard(BhvBlackboard.BHV_OWNER);
        Battle battle = (Battle)getBlackboard(BhvBlackboard.BATTLE);
        List<Effect> activeEffects = (List<Effect>)getBlackboard(BhvBlackboard.BHV_ACTIVE_EFFECTS);

        List<BattleHero> targetHeroes = battle.getBhvProcessor().getBhvTarget().getTargets(bhv);

        for (BattleHero targetHero : targetHeroes) {
            // 依次判断每个目标是否满足当前行为中的每个效果触发条件，获得可以触发的效果
            for (Effect effect : bhv.getEffects()) {
                EftTrgCnd cnd = new EftTrgCnd();
                cnd.init(effect.getMould().getTriggerConditionId(), battle);

                if (cnd.canTrigger(targetHero)) {
                    effect.setTarget(targetHero);
                    activeEffects.add(effect.clone());
                }
            }
        }

        getMch().setState(SInvokeEffect.class);
    }
}
